import com.sun.source.util.Trees;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-11-29
 * Time: 19:24
 */
class Person implements Comparable<Person>{
    String name;
    String sex;
    int age;

    public Person(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    @Override
    public int compareTo(Person o) {
        return this.name.compareTo(o.name);
    }
}
public class MapTest {
    public static void main(String[] args) {
        System.out.println("------map-------");
        Map<String,Integer> map = new TreeMap<>();
        map.put("hello",2);
        map.put("word",4);
        map.put("walk",1);
        System.out.println("map" + map);
        System.out.println(map.getOrDefault("mid", 0));
        System.out.println(map.get("hello"));
        for(Map.Entry<String,Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
        System.out.println("keys:" + map.keySet());
        System.out.println("values:" + map.values());
        System.out.println(map.containsKey("hello"));
        System.out.println(map.containsValue(0));
        System.out.println(map.size());
        map.remove("hello");
        System.out.println(map.size());
        System.out.println("-------Set-------");
        for(Integer num : map.values()) {
            System.out.print(num + " ");
        }
        System.out.println();
        System.out.println("values:" + map.values());
        Set<Person> set = new TreeSet<>();
        Person person = new Person("ss","man",32);
        set.add(person);
        set.add(new Person("qq","woman",38));
        set.add(new Person("kk","woman",34));
        System.out.println(set.size());
        System.out.println(set.contains(person));
        System.out.println(set.contains(new Person("qq", "woman", 38)));
        Person[] array = new Person[set.size()];
        for(Person p : array) {
            if(p != null) {
                System.out.println(p.name + " " + p.sex + " " + p.age);
            }
        }
        Set<String> set1 = new TreeSet<>();
        set1.add("cd");
        set1.add("mk");
        set1.add("rm");
        Iterator<String> it = set1.iterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
        set1.clear();
        System.out.println(set1.isEmpty());
    }
}
